<!-- <template>
	<view>
		<view class="tform">
			<u-form class="form_info" :model="form" ref="uForm">
				<view class="uform">
					<u-form-item class="uform" label="身份信息" label-width='150' label-position="left"
						:label-style="{'font-size':'28rpx','color':'rgba(128, 128, 128, 1)'}"></u-form-item>
					</u-form-item>
				</view>
				<view class="uform">
					<u-form-item prop="name" class="uform" label="姓名" label-width='150' label-position="left"
						:label-style="{'font-size':'24rpx','color':'rgba(56, 56, 56, 1)'}">
						<u-input placeholder="姓名" v-model="form.name" type="text"
							placeholder-style="color:rgba(166, 166, 166, 1);font-size:20rpx"/>
					</u-form-item>
				</view>
				<view class="uform">
					<u-form-item prop="id_number" class="uform" label="证件号码" label-width='150' label-position="left"
						:label-style="{'font-size':'24rpx','color':'rgba(56, 56, 56, 1)'}">
						<u-input placeholder="证件号码" v-model="form.id_number" type="text"
							placeholder-style="color:rgba(166, 166, 166, 1);font-size:20rpx"/>
					</u-form-item>
				</view>
			</u-form>
			<view class="photo_info">
				<u-icon name="info-circle-fill" class="hinticon" size="35" :label="hinttext"
					label-color="rgba(56, 56, 56, 1)">
				</u-icon>
				<view class="imag">
					<u-upload ref="uUpload" max-count="1" width="390" height="220" custom-btn :auto-upload="false"
						@on-choose-complete="afterRead">
						<view slot="addBtn" class="slot-btn slot-btn1">
						</view>
					</u-upload>
					<view class="hinttext" v-if="form.idFrontImg==''">请上传证件照正面</view>
				</view>
				<view class="imag">
					<u-upload ref="uUpload" max-count="1" width="390" height="220" custom-btn :auto-upload="false"
						@on-choose-complete="afterRead1">
						<view slot="addBtn" class="slot-btn slot-btn2">
						</view>
					</u-upload>
					<view class="hinttext" v-if="form.idBackImg==''">请上传证件照反面</view>
				</view>
			</view>
			<button class="submit" :ripple="true" :hair-line="false" @click="submit()">开始认证</button>
		</view>
	</view>

</template>

<script>
	import {
		pathToBase64
	} from '../../../js_sdk/mmmm-image-tools/index.js'
	export default {
		data() {
			return {
				sec: 1,
				hinttext: '请拍摄或上传证件照原件，确保证件真实性！',
				param: {},
				imglist: [],
				form: {
					idBackImg: '',
					idFrontImg: '',
					name: '',
					id_number: ''
				},
				rules: { //验证规则
					name: [{
							required: true,
							message: '请正确上传身份证',
							trigger: ['blur']
						},
						{
							pattern: /^[\u4e00-\u9fa5]+$/,
							message: '请输入正确的姓名',
							trigger: ['blur']
						}
					],
					id_number: [{
							required: true,
							message: '请正确上传身份证',
							trigger: ['blur'],
						},
						{
							validator: (rule, value, callback) => {
								return this.$u.test.idCard(value);
							},
							message: "证件号格式不正确",
							trigger: ['blur']
						}
					]
				}
			}
		},
		methods: {
			afterRead(event) {
				console.log(event)
				this.$upLoadfile({
					url: '/upload/idImgUpload',
					filePath: event[0].url,
					name: 'files'
				}).then(res => {
					if (res.statusCode === 200) {
						let imgurl = JSON.parse(res.data)
						this.form.idFrontImg = imgurl.data; //idFrontImg
					}
				})
			},
			afterRead1(event) {
				this.$upLoadfile({
					url: '/upload/idImgUpload',
					filePath: event[0].url,
					name: 'files'
				}).then(res => {
					if (res.statusCode === 200) {
						let imgurl = JSON.parse(res.data)
						this.form.idBackImg = imgurl.data; //idFrontImg
					}
				})
			},

			async submit() {

				let postdata = {
					'idImgBackPath': this.form.idBackImg,
					'idImgFrontPath': this.form.idFrontImg,
					'idNum': this.form.id_number,
					'realName': this.form.name
				}
				if (this.form.idBackImg == '' || this.form.idFrontImg == '') {
					uni.showToast({
						title: '请上传身份证',
						icon: 'error'
					})
					return 0;
				}
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.$myRequest({
							method: 'POST',
							url: '/certification/idAuthentication',
							data: postdata
						}).then((res) => {
							console.log(res);
							if (res.data.code === 200) {
								getApp().globalData.userinfo.userStatus == 0;
								setTimeout(() => {
									this.goto('../operatesuccess/operatesuccess');
								}, 1000)
							}
						})
					} else {
						console.log('验证失败');
						return 0;
					}
				});
			},
			goto(url) {
				let turl = url + '?delta=3&' + 'successtext=保存成功';
				console.log(turl);
				uni.navigateTo({
					url: turl,
					animationType: 'slide-in-right',
					animationDuration: 1000

				})
			},
			setvalue(i) {
				this.sec = i;
			},
			beforeUpload(res) {
				console.log('上传前', res)
			}
		},
		onReady() { //生命周期
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>

<style>
	@import url("id_photo.css");
</style>
 -->